/**
 * 获取商品的价格
 * @param {Object} info goods 信息
 */
export const getShopGoodsPrice = (info) => {
    let isHaveEnd = false;
    const prices = info.skus.map(item => item.price).sort((a, b) => a - b);
    const start = prices[0];
    const end = prices[prices.length - 1];
    if (start !== end) {
        isHaveEnd = true;
    }
    return {
        start,
        end,
        isHaveEnd,
    };
};

/**
 * 商品添加属性信息
 * @param {Object} goods 商品对象
 * @param {Object} propsInfo 属性信息对象
 */
export const goodsAddProps = (goods, propsInfo) => {
    const { skus } = goods;
    const _skus = (skus || []).map(item => {
        return {
            ...item,
            property_pair: propsInfo.skus.filter(temp => temp.id === item.id)[0].property_pair || [],
        };
    });
    return {
        ...goods,
        prod_nature: propsInfo.prod_nature,
        properties: propsInfo.properties,
        detail_description: propsInfo.detail_description,
        detail_pics: propsInfo.detail_pics,
        title_pics: propsInfo.title_pics,
        skus: _skus,
        unit: propsInfo.unit,
    };
};

/**
 * 商品添加规格信息
 * @param {Object} goods 商品对象
 * @param {Object} skuList 规格数组
 */
export const goodsAddSkus = (goods, skuList) => {
    const { skus } = goods;
    if (!skus) return goods;
    const _skus = skus.map(item => {
        const storage = skuList.filter(temp => temp.sku_id === item.id)[0].storage;
        return {
            ...item,
            storage: storage === -1 ? 999999 : storage,
        };
    });
    return {
        ...goods,
        skus: _skus,
    };
};

export const dealStoreListData = (storeList) => {
    return storeList.filter(item => item.city_express || item.ordinary_express || item.pick_up);
};
